<script>
	import config from '@/app.config.js';
	const db = uniCloud.database();
	export default {
		methods: {},

		// 监听 - 页面404
		onPageNotFound: function(e) {
			uni.redirectTo({
				url: config.error.url
			})
		},
		async onLaunch(options) {},
		async onShow(options) {
			let appid = "tt7f31098ce001544601";
			vk.vuex.set('$app.appid', "tt7f31098ce001544601");
			vk.vuex.set('$app.appname', "七天短剧");

			//设置邀请码保存到本地数据中
			uni.setStorageSync('middleman_id', options.query.middleman_id || 0)
			uni.setStorageSync('invite_code', options.query.invite_code || 0)
			uni.setStorageSync('tfid', options.query.tfid || 0)
			uni.setStorageSync('creativeid', options.query.creativeid || 0)
			uni.setStorageSync('creativetype', options.query.creativetype || 0)
			uni.setStorageSync('clickid', options.query.clickid || 0)
			uni.setStorageSync('promotion_id', options.query.promotionid || 0)
			uni.setStorageSync('projectid', options.query.projectid || 0)


			if (options.query.ad_params) {
				let ad_params = JSON.parse(options.query.ad_params);
				uni.setStorageSync('advertiser_id', ad_params.log_extra.ad_author_id || 0)
				uni.setStorageSync('req_id', ad_params.log_extra.req_id || 0) //202303071521027CF959DD690C4C7F63D5
				uni.setStorageSync('adid', ad_params.ad_id || 0)

			}


			//保存当前设备环境，安卓还是iOS
			uni.getSystemInfo({
				success: (res) => {
					vk.vuex.set('$app.osName', res.osName)
					vk.vuex.set('$app.osName1', "888999")
				}
			});


			const app = await db.collection('a_appid').where({
				appid: appid
			}).get()
			console.log("msglis999999999988888888888888888888888888888888t", app);
			let appinfo = app.result.data[0]
			//定义订阅消息列表
			let msglist = [appinfo.xspsx, appinfo.flhd, appinfo.jjgx];


			vk.vuex.set('$app.msglist', msglist) //订阅消息列表
			vk.vuex.set('$app.appinfo', appinfo) //把appinfo存到本地缓存
			vk.vuex.set('$app.appinfo.appsecret', "0") //安全起见，把appsecret改为0



			//设置常用起始时间
			vk.vuex.set('$app.time', vk.pubfn.getCommonTime(new Date()))
			if (config.debug) console.log('App Show')
		},
		onUnload() {},
		onHide: function() {
			if (config.debug) console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	// @import "./uni_modules/vk-uview-ui/index.scss";
	// @import "./common/css/app.scss";
	@import "./uni_modules/uview-ui/index.scss";
</style>